using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public abstract class Unit_Base : MonoBehaviour
{
    public enum UnitType
    {
        Charactor,
        Interactor,
        Biology,
        Item,
        ItemTrigger,
    }
    public bool isActive=true;
    [SerializeField]
    private SpriteRenderer _renderer;
    public new SpriteRenderer renderer
    {
        get
        {
            //if (_renderer == null)
            //{
            //    _renderer=this.GetComponent<SpriteRenderer>();
            //}
            if (_renderer == null)
            {
                _renderer=this.GetComponentInChildren<SpriteRenderer>();
            }
            return _renderer;
        }
    }



    public abstract UnitType unitType { get; }

    public List<Unit_Base> innerUnits = new List<Unit_Base>();

    protected virtual void OnUnitTriggerEnter(Unit_Base unit_Base)
    {
        if (!innerUnits.Contains(unit_Base))
        {
            innerUnits.Add(unit_Base);
        }
    }
    protected virtual void OnUnitTriggerExit(Unit_Base unit_Base)
    {
        if (innerUnits.Contains(unit_Base))
        {
            innerUnits.Remove(unit_Base);
        }
    }
    public virtual void OnTriggerEnter2D(Collider2D collision)
    {
        Unit_Base unit_Ctrl = collision.GetComponentInParent<Unit_Base>();
        if (unit_Ctrl != null)
        {
            OnUnitTriggerEnter(unit_Ctrl);
        }
    }
    public virtual void OnTriggerExit2D(Collider2D collision)
    {
        Unit_Base unit_Ctrl = collision.GetComponentInParent<Unit_Base>();
        if (unit_Ctrl != null)
        {
            OnUnitTriggerExit(unit_Ctrl);
        }
    }
}
